/*移入*/
function seover(){
    document.getElementById("prev").style.display="block";
    document.getElementById("next").style.display="block";
}
/*移出*/
function seout(){
    document.getElementById("prev").style.display="none";
    document.getElementById("next").style.display="none";
}

var prefix = ctx + "manhua/look";

/*$(function(){
    let search = location.search;
    let data = search.substring(search.indexOf("?")+1,search.length);

    let arr = data.split("&");

    if(data.length>50 && arr[0].split("=")[0] === 'code' && arr[1].split("=")[0] === 'state') {
        $.operate.request("/QQLong", data, function (row) {
            window.history.pushState(null, null, "?");
            /!*关闭遮罩层*!/
            $.modal.closeLoading();
            console.log(row)
            if (row.code === web_status.SUCCESS) {
                console.log("................")
                $(".right-img img").attr("src", row.msg);
            } else {
                $.modal.alertError(row.msg);
            }
        });
    }
})*/

$(function () {
    $.operate.request(prefix + "/indexData", null, function (row) {
        if (row != web_status.SUCCESS) {
            /*关闭遮罩层*/
            $.modal.closeLoading();
            for (let key in row) {
                if (key === 'avatar') {

                    $(".right-img div").css("display","none");

                    $(".right-img img")
                        .css("display","block")
                        .attr("src", row[key]);

                } else if (key === 'eight') {
                    /*第八大行*/
                    $("#articl-1-2").append(avatar(row[key]));
                } else if (key === 'maxFourLine') {
                    /*第三大行*/
                    $("#articl-3").append(maxFourLine(row[key]));
                } else if (key === 'maxThreeMinOneLine') {
                    $("#articl-2-1-left").append(maxThreeMinOneLine(row[key]));
                } else if (key === 'maxThreeMinTwoLine') {
                    /*国漫热*/
                    $("#articl-2-2-right").append(maxThreeMinTwoLine(row[key]));
                } else if (key === 'maxTwoLine') {
                    /*第二大行*/
                    $("#two-articl-1-2").append(avatar(row[key]));
                } else if (key === 'seven') {
                    /*第七大行*/
                    $("#articl-7-box").append(seven(row[key]));
                } else if (key === 'six') {
                    /*第六大行*/
                    $("#articl-6-box").append(six(row[key]));
                } else if (key === 'slideshow') {
                    /*轮播图*/
                    //$("#swiper-wrapper").append(slideshow(row[key]));
                }
            }
        } else {
            $.modal.alertError("出现未知错误。");

        }
    });

})

let maxFourLine = (list) => {
    let html = '<div class="articl-2-1-left-box">';
    for (let i = 0, len = list.length; i < len; i++) {
        let name = list[i].name;
        if (name.length > 5) {
            name = name.substring(0, 5) + "..";
        }
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }
        html += `<div class="article2div-left">
                             <div class="article2div-img">
                                 <a href="/manhua/look/over/${list[i].id}" target="_blank"><img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)"></a>
                             </div>
                              <a href="#">${name}</a>
                             <div class="article2div-span">
                                 <span class="author-name">作者：${author}</span>
                                  <span class="article2div-kan-shuju">${list[i].fond}</span>
                                  <span class="article2div-kan"></span>
                                  <span class="article2div-shouchang-shuju">${list[i].reading}</span>
                                  <span class="article2div-shouchang"></span>
                             </div>
                         </div>`;
        if (i == 4) {
            html += '</div>' +
                '<div class="articl-2-1-left-box">';
        } else if (i == 9) {
            html += '</div>';
        }
    }
    return html;
}
let maxThreeMinOneLine = (list) => {
    let html = '<div class="articl-2-1-left-box">';
    for (let i = 0, len = list.length; i < len; i++) {
        let name = list[i].name;
        if (name.length > 5) {
            name = name.substring(0, 5) + "..";
        }
        let author = list[i].author;
        if (author.length > 4) {
            author = author.substring(0, 4) + "..";
        }
        html += `<div class="article2div-left">
                             <div class="article2div-img">
                                 <a href="/manhua/look/over/${list[i].id}" target="_blank"><img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)"></a>
                             </div>
                              <a href="#">${name}</a>
                             <div class="article2div-span">
                                 <span class="author-name">${author}</span>
                                  <span class="article2div-kan-shuju">${list[i].fond}</span>
                                  <span class="article2div-kan"></span>
                                  <span class="article2div-shouchang-shuju">${list[i].reading}</span>
                                  <span class="article2div-shouchang"></span>
                             </div>
                         </div>`;
        if (i == 3) {
            html += '</div>' +
                '<div class="articl-2-1-left-box">';
        } else if (i == 7) {
            html += '</div>';
        }
    }
    return html;
}
/*国漫热*/
let maxThreeMinTwoLine = (list) => {
    let html = '';
    for (let i = 0, len = list.length; i < len; i++) {
        let name = list[i].name;
        if (name.length > 5) {
            name = name.substring(0, 5) + "..";
        }
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }
        let newZhang = list[i].newZhang === '0' ? '完结' : list[i].newZhang;

        let remark = list[i].remark;
        if (remark.length > 50) {
            remark = remark.substring(0, 50) + "...";
        }

        html += `<div class="articl-2-2-right-1">
                          <div class="articl-2-2-left-box">
                              <a href="/manhua/look/over/${list[i].id}" target="_blank"><img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)"></a>
                          </div>
                          <div class="articl-2-2-right-box">
                              <a href="/manhua/look/over/${list[i].id}" target="_blank">${name}</a>
                              <span>${list[i].typeName}</span>
                              <p>${remark}</p>
                              <p>作者：${author}</p>
                              <p>更新至：<span class="red">${newZhang}</span></p>
                          </div>
                      </div>`;


    }
    return html;
}
/*轮播图*/
let slideshow = (list) => {
    let html = '';
    for (let i = 0, len = list.length; i < len; i++) {

        html += `<div class="swiper-slide" style="width: 100%;">
                            <img data-src="${$.haHa.decode(list[i].theCover)}"  src ="${list[i].theCover}" alt="${list[i].name}" data-srcset="img/picture-1-2x.jpg 2x" class="swiper-lazy" onerror="$.common.errorimg(this)">
                            <div class="swiper-lazy-preloader"></div>
                           </div>`;
    }
    return html;
}
/*第六大行*/
let six = (list) => {
    let html = '';
    for (let i = 0, len = list.length; i < len; i++) {
        let name = list[i].name;
        if (name.length > 15) {
            name = name.substring(0, 15) + "..";
        }
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }
        let remark = list[i].remark;
        if (remark.length > 50) {
            remark = remark.substring(0, 50) + "...";
        }
        html += `<div class="box-6-article2div-left">
                              <div class="box-6-article2div-img">
                                  <a href="/manhua/look/over/${list[i].id}" target="_blank"><img  src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)"/></a>
                              </div>
                              <a href="#">${name}</a>
                              <div class="article2div-span">
                                  <span class="author-name">${author}</span>
                                  <span class="article2div-kan-shuju">${list[i].fond}</span>
                                  <span class="article2div-kan"></span>
                                  <span class="article2div-shouchang-shuju">${list[i].reading}</span>
                                  <span class="article2div-shouchang"></span>
                                  <p>${remark}</p>
                              </div>
                          </div>`;
    }
    return html;
}
/*第七大行*/
let seven = (list) => {
    let html = '<div class="articl-7-box-demo">';
    for (let i = 0, len = list.length; i < len; i++) {
        let name = list[i].name;
        if (name.length > 5) {
            name = name.substring(0, 5) + "..";
        }
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }
        let newZhang = list[i].newZhang === '0' ? '完结' : list[i].newZhang;

        let remark = list[i].remark;
        if (remark.length > 50) {
            remark = remark.substring(0, 50) + "...";
        }
        html += `<div class="articl-2-2-right-1">
                              <div class="articl-7-2-left-box">
                                  <a href="/manhua/look/over/${list[i].id}" target="_blank"><img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)"></a>
                              </div>
                              <div class="articl-7-2-right-box">
                                  <a href="#">${name}</a>
                                  <span>${list[i].typeName}</span>
                                  <p>${remark}</p>
                                  <p>作者：${author}</p>
                                  <p>更新至：<span class="red">${newZhang}</span></p>
                              </div>
                          </div>`;
        if (i == 2) {
            html += '</div>' +
                '<div class="articl-7-box-demo">';
        } else if (i == 5) {
            html += '</div>' +
                '<div class="articl-7-box-demo">';
        } else if (i == 8) {
            html += '</div>';
        }
    }
    return html;
}
/*第八大行*/
let avatar = (list) => {
    let html = '';
    for (let i = 0, len = list.length; i < len; i++) {
        let author = list[i].author;
        if (author.length > 5) {
            author = author.substring(0, 5) + "..";
        }

        let name = list[i].name;
        if (name.length > 6) {
            name = name.substring(0,6) + "..";
        }


        html += `<div class="articl-1-2-box">
                              <a href="/manhua/look/over/${list[i].id}" target="_blank">
                                  <img src="${$.haHa.decode(list[i].theCover)}" alt="${list[i].name}" onerror="$.common.errorimg(this)">
                                  <div>
                                      <span class="articl-1-2-box-left">${author}</span>
                                      <span class="articl-1-2-box-right">${list[i].reading}</span>
                                  </div>
                                  <span>${name}</span>
                              </a>
                          </div>`;
    }
    return html;
}

/*
$("#login").click(function () {
    $.modal.openOptions({
        url:"/login",
        title:"登入",
        height:($(window).height() - 50),
        width:($(window).width()-50),
        btn:false
    });
})*/


var swiper = new Swiper('.swiper-container',{
    autoplay: {
        delay: 5000,
        disableOnInteraction: false,
    },
    speed: 700,
    allowTouchMove: false,
    lazy: {
        loadPrevNext: true,
        loadPrevNextAmount: 3,
    },
    centeredSlides: true,
    spaceBetween : 50,
    slidesOffsetBefore: 40,
    loop: true,
    /*observer:true,//修改swiper自己或子元素时，自动初始化swiper
   observeParents:true,//修改swiper的父元素时，自动初始化swiper*/
    slidesPerView : 'auto',
    on: {
        slideChangeTransitionEnd: function(){
            this.slides.transition(this.params.autoplay.delay+this.params.speed).transform('translate3d(-60px, 0, 0)');
        },
        slideChangeTransitionStart: function(){
            this.slides.transition(this.params.speed).transform('translate3d(0, 0, 0)');
        },
    },
    pagination: {
        el: '.swiper-pagination',
        clickable :true,
        renderBullet: function (index, className) {
            return '<div class="' + className + '"><span></span><i></i></div>';
        },
    },
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
});
window.onresize=function(){
    swiper.update();
}
